/**
 * 作者: hxl
 * 日期: 2025-05-16 18:42:17
 * 备注: 联盟乱斗战报
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUnionScuffleReport;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UnionScuffleReportModel extends BaseModel implements Model {
    public static final String LISTKEY = "act_list_key";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // id
    protected long unionId; // 联盟id
    protected long attackerId; // 挑战者id
    protected String attackerName = ""; // 挑战者名字
    protected long attackUnionId; // 挑战者联盟id
    protected int defeatCount; // 打败成员数量
    protected int subScore; // 扣掉的积分
    protected String attackerIcon = ""; // 挑战者id
    protected String attackUnionName = ""; // 挑战者联盟名称
    protected int matchType; // 匹配类型 (0-随机匹配；1-下战书)
    protected long addTime; // 记录时间
    protected long actId; // 活动id
    protected String actListKey = ""; // 活动分组key

    public void reset() {
    }

    protected String getKey() {
        return "UnionScuffleReport." + id;
    }

    protected String getListKey() {
        return "UnionScuffleReport." + actListKey;
    }

    protected String getListItemKey() {
        return id + "";
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("union_scuffle_report"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, 0, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // id
        obj.put("unionId", unionId); // 联盟id
        obj.put("attackerId", attackerId); // 挑战者id
        obj.put("attackerName", attackerName); // 挑战者名字
        obj.put("attackUnionId", attackUnionId); // 挑战者联盟id
        obj.put("defeatCount", defeatCount); // 打败成员数量
        obj.put("subScore", subScore); // 扣掉的积分
        obj.put("attackerIcon", attackerIcon); // 挑战者id
        obj.put("attackUnionName", attackUnionName); // 挑战者联盟名称
        obj.put("matchType", matchType); // 匹配类型 (0-随机匹配；1-下战书)
        obj.put("addTime", addTime); // 记录时间
        obj.put("actId", actId); // 活动id
        obj.put("actListKey", actListKey); // 活动分组key
        return obj;
    }

    public PBUnionScuffleReport.Builder takeInitBuilder() {
        PBUnionScuffleReport.Builder sb = PBUnionScuffleReport.newBuilder();
        if (attackerId != 0) {
            sb.setAttackerId(attackerId);
        }
        if (!attackerName.isEmpty()) {
            sb.setAttackerName(attackerName);
        }
        if (attackUnionId != 0) {
            sb.setAttackUnionId(attackUnionId);
        }
        if (defeatCount != 0) {
            sb.setDefeatCount(defeatCount);
        }
        if (subScore != 0) {
            sb.setSubScore(subScore);
        }
        if (!attackerIcon.isEmpty()) {
            sb.setAttackerIcon(attackerIcon);
        }
        if (!attackUnionName.isEmpty()) {
            sb.setAttackUnionName(attackUnionName);
        }
        if (matchType != 0) {
            sb.setMatchType(matchType);
        }
        return sb;
    }

    public PBUnionScuffleReport.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUnionScuffleReport.Builder sb = PBUnionScuffleReport.newBuilder();
        if (isFieldUpdate("attackerId")) {
            sb.setAttackerId(attackerId);
        }
        if (isFieldUpdate("attackerName")) {
            sb.setAttackerName(attackerName);
        }
        if (isFieldUpdate("attackUnionId")) {
            sb.setAttackUnionId(attackUnionId);
        }
        if (isFieldUpdate("defeatCount")) {
            sb.setDefeatCount(defeatCount);
        }
        if (isFieldUpdate("subScore")) {
            sb.setSubScore(subScore);
        }
        if (isFieldUpdate("attackerIcon")) {
            sb.setAttackerIcon(attackerIcon);
        }
        if (isFieldUpdate("attackUnionName")) {
            sb.setAttackUnionName(attackUnionName);
        }
        if (isFieldUpdate("matchType")) {
            sb.setMatchType(matchType);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public long getUnionId() {
        return unionId;
    }

    public void putUnionId(long unionId) {
        if (this.unionId != unionId) {
            this.unionId = unionId;
            updateRedisHashField(getKey(), "unionId", this.unionId);
        }
    }

    public void addUnionId(long value) {
        this.unionId += value;
        updateRedisHashField(getKey(), "unionId", this.unionId);
    }

    public long getAttackerId() {
        return attackerId;
    }

    public void putAttackerId(long attackerId) {
        if (this.attackerId != attackerId) {
            this.attackerId = attackerId;
            updateRedisHashField(getKey(), "attackerId", this.attackerId);
        }
    }

    public void addAttackerId(long value) {
        this.attackerId += value;
        updateRedisHashField(getKey(), "attackerId", this.attackerId);
    }

    public String getAttackerName() {
        return attackerName;
    }

    public void putAttackerName(String attackerName) {
        if (!this.attackerName.equals(attackerName)) {
            this.attackerName = attackerName;
            updateRedisHashField(getKey(), "attackerName", this.attackerName);
        }
    }

    public long getAttackUnionId() {
        return attackUnionId;
    }

    public void putAttackUnionId(long attackUnionId) {
        if (this.attackUnionId != attackUnionId) {
            this.attackUnionId = attackUnionId;
            updateRedisHashField(getKey(), "attackUnionId", this.attackUnionId);
        }
    }

    public void addAttackUnionId(long value) {
        this.attackUnionId += value;
        updateRedisHashField(getKey(), "attackUnionId", this.attackUnionId);
    }

    public int getDefeatCount() {
        return defeatCount;
    }

    public void putDefeatCount(int defeatCount) {
        if (this.defeatCount != defeatCount) {
            this.defeatCount = defeatCount;
            updateRedisHashField(getKey(), "defeatCount", this.defeatCount);
        }
    }

    public void addDefeatCount(int value) {
        this.defeatCount += value;
        updateRedisHashField(getKey(), "defeatCount", this.defeatCount);
    }

    public int getSubScore() {
        return subScore;
    }

    public void putSubScore(int subScore) {
        if (this.subScore != subScore) {
            this.subScore = subScore;
            updateRedisHashField(getKey(), "subScore", this.subScore);
        }
    }

    public void addSubScore(int value) {
        this.subScore += value;
        updateRedisHashField(getKey(), "subScore", this.subScore);
    }

    public String getAttackerIcon() {
        return attackerIcon;
    }

    public void putAttackerIcon(String attackerIcon) {
        if (!this.attackerIcon.equals(attackerIcon)) {
            this.attackerIcon = attackerIcon;
            updateRedisHashField(getKey(), "attackerIcon", this.attackerIcon);
        }
    }

    public String getAttackUnionName() {
        return attackUnionName;
    }

    public void putAttackUnionName(String attackUnionName) {
        if (!this.attackUnionName.equals(attackUnionName)) {
            this.attackUnionName = attackUnionName;
            updateRedisHashField(getKey(), "attackUnionName", this.attackUnionName);
        }
    }

    public int getMatchType() {
        return matchType;
    }

    public void putMatchType(int matchType) {
        if (this.matchType != matchType) {
            this.matchType = matchType;
            updateRedisHashField(getKey(), "matchType", this.matchType);
        }
    }

    public void addMatchType(int value) {
        this.matchType += value;
        updateRedisHashField(getKey(), "matchType", this.matchType);
    }

    public long getAddTime() {
        return addTime;
    }

    public void putAddTime(long addTime) {
        if (this.addTime != addTime) {
            this.addTime = addTime;
            updateRedisHashField(getKey(), "addTime", this.addTime);
        }
    }

    public void addAddTime(long value) {
        this.addTime += value;
        updateRedisHashField(getKey(), "addTime", this.addTime);
    }

    public long getActId() {
        return actId;
    }

    public void putActId(long actId) {
        if (this.actId != actId) {
            this.actId = actId;
            updateRedisHashField(getKey(), "actId", this.actId);
        }
    }

    public void addActId(long value) {
        this.actId += value;
        updateRedisHashField(getKey(), "actId", this.actId);
    }

    public String getActListKey() {
        return actListKey;
    }

    public void putActListKey(String actListKey) {
        if (!this.actListKey.equals(actListKey)) {
            this.actListKey = actListKey;
            updateRedisHashField(getKey(), "actListKey", this.actListKey);
        }
    }

}